<?php

namespace App\Admin\Extensions\Tools\Message;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;
use Illuminate\Support\Facades\Request;

class MessagePublished extends AbstractTool
{
    protected function script()
    {
        $status = Request::get('status') ? Request::get('status') : 'all';
        $url = Request::fullUrlWithQuery(['published' => '_published_', 'status' => $status]);

        return <<<EOT

$('input:radio.message-published').change(function () {

    var url = "$url".replace('_published_', $(this).val());

    $.pjax({container:'#pjax-container', url: url });

});

EOT;
    }

    public function render()
    {
        Admin::script($this->script());
        $options = [
            'all'   => '所有',
            'on'     => '已发布',
            'off'     => '未发布',
        ];
        return view('admin.tools.message.message-published', compact('options'));
    }
}